package com.deductive.service.special.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.deductive.domain.special.SpecialData;
import com.deductive.mapper.PgDBMapper;
import com.deductive.mapper.special.SpecialDataMapper;
import com.deductive.service.special.SpecialDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 王浩
 * @createDate 2025-03-19 16:52:55
 */
@Service
@Slf4j
public class SpecialDataServiceImpl extends ServiceImpl<SpecialDataMapper, SpecialData>
        implements SpecialDataService {

    @Autowired
    private PgDBMapper pgDBMapper;

    public String createTableSql(String tableName, String columnName, String srId) {
        String sql = String.format("DROP TABLE IF EXISTS \"public\".\"%s\";\n" +
                "CREATE TABLE \"public\".\"%s\" (\n" +
                "   \"id\" int8 NOT NULL GENERATED ALWAYS AS IDENTITY (\n" +
                "INCREMENT 1\n" +
                "MINVALUE  1\n" +
                "MAXVALUE 9223372036854775807\n" +
                "START 1\n" +
                "CACHE 1\n" +
                "),\n" +
                "  \"geom\" geometry(GEOMETRY, %s),\n" +
                "  %s\n" +
                ")\n" +
                ";\n" +
                "\n" +
                "ALTER TABLE \"public\".\"%s\" ADD CONSTRAINT \"%s_pkey\" PRIMARY KEY (\"id\");\n", tableName, tableName, srId, columnName, tableName, tableName);
        return sql;
    }

}




